home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr52 / saveke.zip / SAVEKEY.PRG
Text File  |  1993-04-22  |  12KB  |  295 lines

  1. /*
  2.  * File......: SAVEKEY.PRG
  3.  * Author....: Dale Armstrong 
  4.  * CIS ID....: 72730, 1104
  5.  * Date......: $Date:   
  6.  * Revision..: $Revision:
  7.  * Log file..: $Logfile:
  8.  *
  9.  * This is an original work by Dale Armstrong and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:
  16.  * 
  17.  */
  18.  
  19. /*  $DOC$
  20.  *  $FUNCNAME$
  21.  *     FT_SAVEKEY()
  22.  *  $CATEGORY$
  23.  *     Keyboard/Mouse
  24.  *  $ONELINER$
  25.  *     Save the status of all SetKeys to an array.
  26.  *  $SYNTAX$
  27.  *     FT_SAVEKEY() -> aRet
  28.  *  $ARGUMENTS$
  29.  *  $RETURNS$
  30.  *     a multi-dimensional array of the following definition:
  31.  *     { { <Inkey Code>, <SetKey() Value> } }. 
  32.  *  $DESCRIPTION$
  33.  *     FT_SAVEKEY() saves the status of all SetKeys() to a
  34.  *     multi-dimensional array for later restoration 
  35.  *     using the function FT_RESTKEY(). 
  36.  *
  37.  *     The SetKey definitions have been taken from the Clipper 
  38.  *     Header file "inkey.ch" provided by Nantucket.
  39.  *
  40.  *     This effectively disables the access to hotkeys 
  41.  *     when necessary, i.e., to stop recursion, or to limit
  42.  *     the user's actions while in other routines such as a
  43.  *     call to help.
  44.  *  $EXAMPLES$
  45.  *
  46.  *     // called by the F1 key, Clipper 5.01 default 
  47.  *     FUNCTION help( <Proc>, <Line>, <Var> )
  48.  *        LOCAL aOldSetKeys
  49.  *        .. other variable declarations
  50.  *
  51.  *        // store all SET KEY's 
  52.  *        aOldSetKeys := FT_SAVEKEY()
  53.  *   
  54.  *        .. program's code
  55.  *     
  56.  *        // restore old KEY SET's
  57.  *        FT_RESTKEY( aOldSetKeys )
  58.  *
  59.  *     RETURN nil
  60.  *  $SEEALSO$
  61.  *     FT_SAVEKEY()
  62.  *  $END$
  63.  */
  64.  
  65. #include "inkey.ch"
  66.  
  67. FUNCTION SaveKeys()
  68. LOCAL aSetKey := {}
  69.  
  70.         // Cursor movement keys
  71.         aAdd( aSetKey, {  K_UP  , SetKey(  5 ) } )            // Uparrow, Ctrl-E
  72.         aAdd( aSetKey, {  K_DOWN , SetKey( 24) } )            // Dnarrow, Ctrl-X
  73.         aAdd( aSetKey, {  K_LEFT , SetKey( 19) } )            // Leftarrow, Ctrl-S
  74.         aAdd( aSetKey, {  K_RIGHT, SetKey( 4 ) } )            // Rightarrow, Ctrl-D
  75.         aAdd( aSetKey, {  K_HOME , SetKey( 1 ) } )            // Home, Ctrl-A
  76.         aAdd( aSetKey, {  K_END  , SetKey( 6 ) } )            // End, Ctrl-F
  77.         aAdd( aSetKey, {  K_PGUP , SetKey( 18) } )            // PgUp, Ctrl-R
  78.         aAdd( aSetKey, {  K_PGDN , SetKey( 3 ) } )            // PgDn, Ctrl-C
  79.         aAdd( aSetKey, {  K_CTRL_LEFT  , SetKey( 26) } )    // Ctrl-Leftarrow, Ctrl-Z
  80.         aAdd( aSetKey, {  K_CTRL_RIGHT , SetKey( 2 ) } )    // Ctrl-Rightarrow, Ctrl-B
  81.         aAdd( aSetKey, {  K_CTRL_UP , SetKey( 397  ) } )    // Ctrl-Uparrow
  82.         aAdd( aSetKey, {  K_CTRL_DOWN  , SetKey( 401  ) } )    // Ctrl-Dnarrow
  83.         aAdd( aSetKey, {  K_CTRL_HOME  , SetKey( 29) } )    // Ctrl-Home, Ctrl-]
  84.         aAdd( aSetKey, {  K_CTRL_END, SetKey( 23) } )        // Ctrl-End, Ctrl-W
  85.         aAdd( aSetKey, {  K_CTRL_PGUP  , SetKey( 31) } )    // Ctrl-PgUp, Ctrl-Hyphen
  86.         aAdd( aSetKey, {  K_CTRL_PGDN  , SetKey( 30) } )    // Ctrl-PgDn, Ctrl-^
  87.         aAdd( aSetKey, {  K_CTRL_RET, SetKey( 10) } )        // Ctrl-Return
  88.         
  89.         aAdd( aSetKey, {  K_ESC  , SetKey( 27) } )            // Esc, Ctrl-[
  90.         aAdd( aSetKey, {  K_RETURN  , SetKey( 13) } )        // Return, Ctrl-M
  91.         aAdd( aSetKey, {  K_ENTER, SetKey( 13) } )            // Enter, Ctrl-M
  92.         
  93.         // Editing keys
  94.         aAdd( aSetKey, {  K_INS  , SetKey( 22) } )            // Ins, Ctrl-V
  95.         aAdd( aSetKey, {  K_DEL  , SetKey( 7 ) } )            // Del, Ctrl-G
  96.         aAdd( aSetKey, {  K_BS, SetKey( 8 ) } )                // Backspace, Ctrl-H
  97.         aAdd( aSetKey, {  K_CTRL_BS , SetKey( 127  ) } )    // Ctrl-Backspace
  98.         aAdd( aSetKey, {  K_TAB  , SetKey( 9 ) } )            // Tab, Ctrl-I
  99.         aAdd( aSetKey, {  K_SH_TAB  , SetKey( 271  ) } )    // Shift-Tab
  100.         
  101.         // Numeric keys
  102.         aAdd( aSetKey, {  K_1  , SetKey( 49 ) } )
  103.         aAdd( aSetKey, {  K_2  , SetKey( 50 ) } )
  104.         aAdd( aSetKey, {  K_3  , SetKey( 51 ) } )
  105.         aAdd( aSetKey, {  K_4  , SetKey( 52 ) } )
  106.         aAdd( aSetKey, {  K_5  , SetKey( 53 ) } )
  107.         aAdd( aSetKey, {  K_6  , SetKey( 54 ) } )
  108.         aAdd( aSetKey, {  K_7  , SetKey( 55 ) } )
  109.         aAdd( aSetKey, {  K_8  , SetKey( 56 ) } )
  110.         aAdd( aSetKey, {  K_9  , SetKey( 57 ) } )
  111.         aAdd( aSetKey, {  K_0  , SetKey( 48 ) } )
  112.         
  113.         
  114.         // Control keys
  115.         aAdd( aSetKey, {  K_CTRL_DEL , SetKey( 403 ) } )    // Ctrl-DEL
  116.         aAdd( aSetKey, {  K_CTRL_A, SetKey(1 ) } )            // Ctrl-A, Home
  117.         aAdd( aSetKey, {  K_CTRL_B, SetKey(2 ) } )            // Ctrl-B, Ctrl-Rightarrow
  118.         aAdd( aSetKey, {  K_CTRL_C, SetKey(3 ) } )            // Ctrl-C, PgDn, Ctrl-ScrollLock
  119.         aAdd( aSetKey, {  K_CTRL_D, SetKey(4 ) } )            // Ctrl-D, Rightarrow
  120.         aAdd( aSetKey, {  K_CTRL_E, SetKey(5 ) } )            // Ctrl-E, Uparrow
  121.         aAdd( aSetKey, {  K_CTRL_F, SetKey(6 ) } )            // Ctrl-F, End
  122.         aAdd( aSetKey, {  K_CTRL_G, SetKey(7 ) } )            // Ctrl-G, Del
  123.         aAdd( aSetKey, {  K_CTRL_H, SetKey(8 ) } )            // Ctrl-H, Backspace
  124.         aAdd( aSetKey, {  K_CTRL_I, SetKey(9 ) } )            // Ctrl-I, Tab
  125.         aAdd( aSetKey, {  K_CTRL_J, SetKey(10) } )            // Ctrl-J
  126.         aAdd( aSetKey, {  K_CTRL_K, SetKey(11) } )            // Ctrl-K
  127.         aAdd( aSetKey, {  K_CTRL_L, SetKey(12) } )            // Ctrl-L
  128.         aAdd( aSetKey, {  K_CTRL_M, SetKey(13) } )            // Ctrl-M, Return
  129.         aAdd( aSetKey, {  K_CTRL_N, SetKey(14) } )            // Ctrl-N
  130.         aAdd( aSetKey, {  K_CTRL_O, SetKey(15) } )            // Ctrl-O
  131.         aAdd( aSetKey, {  K_CTRL_P, SetKey(16) } )            // Ctrl-P
  132.         aAdd( aSetKey, {  K_CTRL_Q, SetKey(17) } )            // Ctrl-Q
  133.         aAdd( aSetKey, {  K_CTRL_R, SetKey(18) } )            // Ctrl-R, PgUp
  134.         aAdd( aSetKey, {  K_CTRL_S, SetKey(19) } )            // Ctrl-S, Leftarrow
  135.         aAdd( aSetKey, {  K_CTRL_T, SetKey(20) } )            // Ctrl-T
  136.         aAdd( aSetKey, {  K_CTRL_U, SetKey(21) } )            // Ctrl-U
  137.         aAdd( aSetKey, {  K_CTRL_V, SetKey(22) } )            // Ctrl-V, Ins
  138.         aAdd( aSetKey, {  K_CTRL_W, SetKey(23) } )            // Ctrl-W, Ctrl-End
  139.         aAdd( aSetKey, {  K_CTRL_X, SetKey(24) } )            // Ctrl-X, Dnarrow
  140.         aAdd( aSetKey, {  K_CTRL_Y, SetKey(25) } )            // Ctrl-Y
  141.         aAdd( aSetKey, {  K_CTRL_Z, SetKey(26) } )            // Ctrl-Z, Ctrl-Leftarrow
  142.         
  143.         
  144.         // Alt keys
  145.         aAdd( aSetKey, {  K_ALT_A, SetKey( 286  ) } )        // Alt-A
  146.         aAdd( aSetKey, {  K_ALT_B, SetKey( 304  ) } )        // Alt-B
  147.         aAdd( aSetKey, {  K_ALT_C, SetKey( 302  ) } )        // Alt-C
  148.         aAdd( aSetKey, {  K_ALT_D, SetKey( 288  ) } )        // Alt-D
  149.         aAdd( aSetKey, {  K_ALT_E, SetKey( 274  ) } )        // Alt-E
  150.         aAdd( aSetKey, {  K_ALT_F, SetKey( 289  ) } )        // Alt-F
  151.         aAdd( aSetKey, {  K_ALT_G, SetKey( 290  ) } )        // Alt-G
  152.         aAdd( aSetKey, {  K_ALT_H, SetKey( 291  ) } )        // Alt-H
  153.         aAdd( aSetKey, {  K_ALT_I, SetKey( 279  ) } )        // Alt-I
  154.         aAdd( aSetKey, {  K_ALT_J, SetKey( 292  ) } )        // Alt-J
  155.         aAdd( aSetKey, {  K_ALT_K, SetKey( 293  ) } )        // Alt-K
  156.         aAdd( aSetKey, {  K_ALT_L, SetKey( 294  ) } )        // Alt-L
  157.         aAdd( aSetKey, {  K_ALT_M, SetKey( 306  ) } )        // Alt-M
  158.         aAdd( aSetKey, {  K_ALT_N, SetKey( 305  ) } )        // Alt-N
  159.         aAdd( aSetKey, {  K_ALT_O, SetKey( 280  ) } )        // Alt-O
  160.         aAdd( aSetKey, {  K_ALT_P, SetKey( 281  ) } )        // Alt-P
  161.         aAdd( aSetKey, {  K_ALT_Q, SetKey( 272  ) } )        // Alt-Q
  162.         aAdd( aSetKey, {  K_ALT_R, SetKey( 275  ) } )        // Alt-R
  163.         aAdd( aSetKey, {  K_ALT_S, SetKey( 287  ) } )        // Alt-S
  164.         aAdd( aSetKey, {  K_ALT_T, SetKey( 276  ) } )        // Alt-T
  165.         aAdd( aSetKey, {  K_ALT_U, SetKey( 278  ) } )        // Alt-U
  166.         aAdd( aSetKey, {  K_ALT_V, SetKey( 303  ) } )        // Alt-V
  167.         aAdd( aSetKey, {  K_ALT_W, SetKey( 273  ) } )        // Alt-W
  168.         aAdd( aSetKey, {  K_ALT_X, SetKey( 301  ) } )        // Alt-X
  169.         aAdd( aSetKey, {  K_ALT_Y, SetKey( 277  ) } )        // Alt-Y
  170.         aAdd( aSetKey, {  K_ALT_Z, SetKey( 300  ) } )        // Alt-Z
  171.         aAdd( aSetKey, {  K_ALT_1, SetKey( 376  ) } )        // Alt-1
  172.         aAdd( aSetKey, {  K_ALT_2, SetKey( 377  ) } )        // Alt-2
  173.         aAdd( aSetKey, {  K_ALT_3, SetKey( 378  ) } )        // Alt-3
  174.         aAdd( aSetKey, {  K_ALT_4, SetKey( 379  ) } )        // Alt-4
  175.         aAdd( aSetKey, {  K_ALT_5, SetKey( 380  ) } )        // Alt-5
  176.         aAdd( aSetKey, {  K_ALT_6, SetKey( 381  ) } )        // Alt-6
  177.         aAdd( aSetKey, {  K_ALT_7, SetKey( 382  ) } )        // Alt-7
  178.         aAdd( aSetKey, {  K_ALT_8, SetKey( 383  ) } )        // Alt-8
  179.         aAdd( aSetKey, {  K_ALT_9, SetKey( 384  ) } )        // Alt-9
  180.         aAdd( aSetKey, {  K_ALT_0, SetKey( 385  ) } )        // Alt-0
  181.         
  182.         // Function keys
  183.         aAdd( aSetKey, {  K_F1, SetKey( 28) } )        // F1, Ctrl-\
  184.         aAdd( aSetKey, {  K_F2, SetKey( -1) } )        // F2
  185.         aAdd( aSetKey, {  K_F3, SetKey( -2) } )        // F3
  186.         aAdd( aSetKey, {  K_F4, SetKey( -3) } )        // F4
  187.         aAdd( aSetKey, {  K_F5, SetKey( -4) } )        // F5
  188.         aAdd( aSetKey, {  K_F6, SetKey( -5) } )        // F6
  189.         aAdd( aSetKey, {  K_F7, SetKey( -6) } )        // F7
  190.         aAdd( aSetKey, {  K_F8, SetKey( -7) } )        // F8
  191.         aAdd( aSetKey, {  K_F9, SetKey( -8) } )        // F9
  192.         aAdd( aSetKey, {  K_F10  , SetKey( -9) } )    // F10
  193.         aAdd( aSetKey, {  K_F11  , SetKey( -40  ) } )    // F11
  194.         aAdd( aSetKey, {  K_F12  , SetKey( -41  ) } )    // F12
  195.         
  196.         // Control-function keys
  197.         aAdd( aSetKey, {  K_CTRL_F1 , SetKey( -20  ) } )        // Ctrl-F1
  198.         aAdd( aSetKey, {  K_CTRL_F2 , SetKey( -21  ) } )        // Ctrl-F2
  199.         aAdd( aSetKey, {  K_CTRL_F3 , SetKey( -22  ) } )        // Ctrl-F4
  200.         aAdd( aSetKey, {  K_CTRL_F4 , SetKey( -23  ) } )        // Ctrl-F3
  201.         aAdd( aSetKey, {  K_CTRL_F5 , SetKey( -24  ) } )        // Ctrl-F5
  202.         aAdd( aSetKey, {  K_CTRL_F6 , SetKey( -25  ) } )        // Ctrl-F6
  203.         aAdd( aSetKey, {  K_CTRL_F7 , SetKey( -26  ) } )        // Ctrl-F7
  204.         aAdd( aSetKey, {  K_CTRL_F8 , SetKey( -27  ) } )        // Ctrl-F8
  205.         aAdd( aSetKey, {  K_CTRL_F9 , SetKey( -28  ) } )        // Ctrl-F9
  206.         aAdd( aSetKey, {  K_CTRL_F10, SetKey( -29  ) } )        // Ctrl-F10
  207.         aAdd( aSetKey, {  K_CTRL_F11, SetKey( -44  ) } )        // Ctrl-F11
  208.         aAdd( aSetKey, {  K_CTRL_F12, SetKey( -45  ) } )        // Ctrl-F12
  209.         
  210.         // Alt-function keys
  211.         aAdd( aSetKey, {  K_ALT_F1  , SetKey( -30  ) } )        // Alt-F1
  212.         aAdd( aSetKey, {  K_ALT_F2  , SetKey( -31  ) } )        // Alt-F2
  213.         aAdd( aSetKey, {  K_ALT_F3  , SetKey( -32  ) } )        // Alt-F3
  214.         aAdd( aSetKey, {  K_ALT_F4  , SetKey( -33  ) } )        // Alt-F4
  215.         aAdd( aSetKey, {  K_ALT_F5  , SetKey( -34  ) } )        // Alt-F5
  216.         aAdd( aSetKey, {  K_ALT_F6  , SetKey( -35  ) } )        // Alt-F6
  217.         aAdd( aSetKey, {  K_ALT_F7  , SetKey( -36  ) } )        // Alt-F7
  218.         aAdd( aSetKey, {  K_ALT_F8  , SetKey( -37  ) } )        // Alt-F8
  219.         aAdd( aSetKey, {  K_ALT_F9  , SetKey( -38  ) } )        // Alt-F9
  220.         aAdd( aSetKey, {  K_ALT_F10 , SetKey( -39  ) } )        // Alt-F10
  221.         aAdd( aSetKey, {  K_ALT_F11 , SetKey( -46  ) } )        // Alt-F11
  222.         aAdd( aSetKey, {  K_ALT_F12 , SetKey( -47  ) } )        // Alt-F12
  223.         
  224.         // Shift-function keys
  225.         aAdd( aSetKey, {  K_SH_F1, SetKey( -10  ) } )        // Shift-F1
  226.         aAdd( aSetKey, {  K_SH_F2, SetKey( -11  ) } )        // Shift-F2
  227.         aAdd( aSetKey, {  K_SH_F3, SetKey( -12  ) } )        // Shift-F3
  228.         aAdd( aSetKey, {  K_SH_F4, SetKey( -13  ) } )        // Shift-F4
  229.         aAdd( aSetKey, {  K_SH_F5, SetKey( -14  ) } )        // Shift-F5
  230.         aAdd( aSetKey, {  K_SH_F6, SetKey( -15  ) } )        // Shift-F6
  231.         aAdd( aSetKey, {  K_SH_F7, SetKey( -16  ) } )        // Shift-F7
  232.         aAdd( aSetKey, {  K_SH_F8, SetKey( -17  ) } )        // Shift-F8
  233.         aAdd( aSetKey, {  K_SH_F9, SetKey( -18  ) } )        // Shift-F9
  234.         aAdd( aSetKey, {  K_SH_F10  , SetKey( -19  ) } )    // Shift-F10
  235.         aAdd( aSetKey, {  K_SH_F11  , SetKey( -42  ) } )    // Shift-F11
  236.         aAdd( aSetKey, {  K_SH_F12  , SetKey( -43  ) } )    // Shift-F12
  237.         
  238.         aEval( aSetKey, { |aSub| SetKey( aSub[1], NIL )  } )   
  239.  
  240. RETURN aSetKey
  241.  
  242. /*  $DOC$
  243.  *  $FUNCNAME$
  244.  *     FT_RESTKEY()
  245.  *  $CATEGORY$
  246.  *     Keyboard/Mouse
  247.  *  $ONELINER$
  248.  *     Restore the status of all SetKeys from an array.
  249.  *  $SYNTAX$
  250.  *     FT_RESTKEY( <aToRestore> ) -> NIL
  251.  *  $ARGUMENTS$
  252.  *     <aToRestore> is a multi-dimensional array, created by
  253.  *     the function FT_SAVEKEY, of the following definition:
  254.  *     { { <Inkey Code>, <SetKey() Value> } }. 
  255.  *  $RETURNS$
  256.  *     NIL
  257.  *  $DESCRIPTION$
  258.  *     FT_RESTKEY() restores the status of all SetKeys() from
  259.  *     a multi-dimensional array created by the function 
  260.  *     FT_SAVEKEY(). 
  261.  *
  262.  *     The SetKey definitions have been taken from the Clipper 
  263.  *     Header file "inkey.ch" provided by Nantucket.
  264.  *
  265.  *     This effectively re-enables the access to hotkeys 
  266.  *     when returning from another routine such as a
  267.  *     call to help.
  268.  *  $EXAMPLES$
  269.  *
  270.  *     // called by the F1 key, Clipper 5.01 default 
  271.  *     FUNCTION help( <Proc>, <Line>, <Var> )
  272.  *        LOCAL aOldSetKeys
  273.  *        .. other variable declarations
  274.  *
  275.  *        // store all SET KEY's 
  276.  *        aOldSetKeys := FT_SAVEKEY()
  277.  *   
  278.  *        .. program's code
  279.  *     
  280.  *        // restore old KEY SET's
  281.  *        FT_RESTKEY( aOldSetKeys )
  282.  *
  283.  *     RETURN nil
  284.  *  $SEEALSO$
  285.  *     FT_SAVEKEY()
  286.  *  $END$
  287.  */
  288. FUNCTION RestKeys( aPassed )
  289.  
  290.     /* reset all the SET KEY's */
  291.     aEval( aPassed, { | aSub | SetKey( aSub[1], aSub[2] ) } )
  292.  
  293. RETURN nil
  294.  
  295.